/*
 * @Description: 
 * @Version: 2.0
 * @Autor: ftt
 * @Date: 2022-06-14 14:23:48
 * @LastEditors: TT
 * @LastEditTime: 2022-06-20 15:22:53
 */

import 'package:hzy_normal_widget/hzy_normal_widget.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../components/common_index.dart';
import '../../../config/controller/user_state_controller.dart';
import '../../../utils/utils_tool.dart';

class HomeListC extends CommonGetXListController {
  RxList list = RxList();

  var itemw = ((SizeMacro.screenWidth - 45.w) / 2).obs;
  var multiple = true.obs;
  var centerbtny = (SizeMacro.screenWidth - 70.w) / 2;

  @override
  void onReady() {
    super.onReady();
    if (UserStateController.isLogin) {
      getnetworkdata(3, null);
    } else {
      pageState.value = PageState.emptyDataState;
    }
  }

  @override
  void getnetworkdata(int? type, Map<String, dynamic>? info) {
    if (page == 1) {
      list.clear();
    }
    List info = [];
    for (var i = 0; i < configRandom(4); i++) {
      info.add("$i");
    }
    debugprint(info.length);
    list.addAll(info);

    /// 正常数据回调 ,也可以在这里 进行数据加载失败判断,由于模拟数据,
    /// 这里就只显示正常情况
    /// 如果想模拟 失败情况 使用
    /// 错误状态,显示失败界面
    /// errorState,
    /// 错误状态,只弹错误信息
    /// erroronlyTotal,
    /// 错误状态,显示刷新按钮
    /// errorshowRelesh,
    ///
    pageState.value = PageState.dataFetchState;

    // 判断数据 是否为空
    if (list.isEmpty) {
      pageState.value = PageState.emptyDataState;
      placeHoldType = CommonPlaceHoldType.nothing;
    } else if (info.isEmpty) {
      // 判断数据 是否有更多数据
      pageState.value = PageState.noMoreDataState;
    }
    endRefresh(type: type, state: pageState.value);
  }

  changeItemW() {
    multiple.value = !multiple.value;
    if (!multiple.value) {
      itemw.value = SizeMacro.screenWidth - 30.w;
    } else {
      itemw.value = ((SizeMacro.screenWidth - 45.w) / 2);
    }
  }
}
